<?php 

defined('_JEXEC') or die;

// disable core styles to avoid bs conflict 
OC_Util::$core_styles = array();

if(isDevMode()) {
   OCP\Util::addStyle('company', 'company');
   OCP\Util::addStyle('calendar', 'calendar.common');
   OCP\Util::addScript('company', 'home');
   OCP\Util::addScript('company', 'autoactions');
} else {
   OCP\Util::addStyle('static', 'company');
   OCP\Util::addScript('static', 'apps/company.home.min');
   OCP\Util::addScript('static', 'apps/company.autoactions.min');
}


OCP\App::setActiveNavigationEntry('company_index');

$lang = PFactory::getLanguage();
$lang->load("com_jobs", JPATH_SITE, "zh-CN");

$thirdaccounts_info = $_['thirdaccounts_info'];
$thirdaccounts_status = $_['thirdaccounts_status'];
$isJobManagerViewOnly = $_['isJobManagerViewOnly'];
if(!$isJobManagerViewOnly){
   $totalresumes = $_['totalresumes'];
   $totalinterview = $_['totalinterview'];
}
$thirdaccount_51job = empty($thirdaccounts_info['51job']) ? null : $thirdaccounts_info['51job'];
$thirdaccount_zhilian = empty($thirdaccounts_info['zhilian']) ? null : $thirdaccounts_info['zhilian'];
$thirdaccount_lagou = empty($thirdaccounts_info['lagou']) ? null : $thirdaccounts_info['lagou'];
$thirdaccount_jiancai = empty($thirdaccounts_info['jiancai']) ? null : $thirdaccounts_info['jiancai'];
$thirdaccount_status_51job = empty($thirdaccounts_status['51job']['fetchjobs']) ? null : $thirdaccounts_status['51job']['fetchjobs'];
$thirdaccount_status_zhilian = empty($thirdaccounts_status['zhilian']['fetchjobs']) ? null : $thirdaccounts_status['zhilian']['fetchjobs'];
$thirdaccount_status_lagou = empty($thirdaccounts_status['lagou']['fetchjobs']) ? null : $thirdaccounts_status['lagou']['fetchjobs'];
$thirdaccount_status_jiancai = empty($thirdaccounts_status['jiancai']['fetchjobs']) ? null : $thirdaccounts_status['jiancai']['fetchjobs'];

$autofetchjobsinfo51job = !isset($thirdaccounts_status['51job']['autofetchjobs']) ? null : $thirdaccounts_status['51job']['autofetchjobs'];
$autofetchjobsinfozhilian = !isset($thirdaccounts_status['zhilian']['autofetchjobs']) ? null : $thirdaccounts_status['zhilian']['autofetchjobs'];
$autofetchjobsinfolagou = !isset($thirdaccounts_status['lagou']['autofetchjobs']) ? null : $thirdaccounts_status['lagou']['autofetchjobs'];
$autofetchjobsinfojiancai = !isset($thirdaccounts_status['jiancai']['autofetchjobs']) ? null : $thirdaccounts_status['jiancai']['autofetchjobs'];

$autofetchjobs_on_51job = ($autofetchjobsinfo51job === null || (isset($autofetchjobsinfo51job['disabled']) && $autofetchjobsinfo51job['disabled'] == 1))? 0 : 1;
$autofetchjobs_on_zhilian = ($autofetchjobsinfozhilian === null || (isset($autofetchjobsinfozhilian['disabled']) && $autofetchjobsinfozhilian['disabled'] == 1) || (isset($autofetchjobsinfozhilian['result']) && $autofetchjobsinfozhilian['result'] == 'captcha'))? 0 : 1;
$autofetchjobs_on_lagou = ($autofetchjobsinfolagou === null || (isset($autofetchjobsinfolagou['disabled']) && $autofetchjobsinfolagou['disabled'] == 1) || (isset($autofetchjobsinfolagou['result']) && $autofetchjobsinfolagou['result'] == 'captcha'))? 0 : 1;
$autofetchjobs_on_jiancai = ($autofetchjobsinfojiancai === null || (isset($autofetchjobsinfojiancai['disabled']) && $autofetchjobsinfojiancai['disabled'] == 1))? 0 : 1;

$user = $_['user'];
$subuser = PCompanyHelper::getSubUser();
$masteruserinfo=$_['masteruserinfo'];
?>
<script type="text/javascript" src="<?php print_unescaped(OC_Helper::linkTo('company/js', 'company.php'));?>"></script>

<div class="hr_companycenter_set" id="companycenter">

   <div class="hr_companycenter_top clearfix">
      <div class="hr_complogo pull-left"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td><?php echo JobHelper::getUserAvatar($_['masteruserinfo'],false); ?></td></tr></table></div>
      <div class="hr_companycenter_name pull-left">
   		<h4 class="large">您好，<?=$user?><i class="<? echo $masteruserinfo->validated == EMPLOYER_VALIDATED ? "is_approve" : "not_approve";?>"></i></h4>
      	<div class="medium"><a target="_blank" href="<?=OCP\Util::linkToRoute('jobpos_index')?>">职位（<?=$_['stats']['jobs']['totaljobs']?>）</a><a target="_blank" href="<?=OCP\Util::linkToRoute('resumes_index')?>">简历（<?=$_['stats']['resumes']['totalresumes']?>）</a></div>
      </div>
   </div>
   <div class="hr_companycenter_wrapper">
      <div class="hr_netaddress">
         <span>公 司 主 页：</span>
         <a id="homelink" target='_blank' href="<?=PCompanyHelper::getHomeLink()?>"><?=PCompanyHelper::getHomeLink()?></a>
      </div>
      <div class="company_twolevel clearfix">
         <?php if ($subuser->permissions & PERMISSION_JOB_CRUD && $subuser->permissions & PERMISSION_JOB_ADMIN_ALL): ?>
         <div class="hr_netaddress hr_widgetsbox pull-left" style="margin-bottom:0px; width:53%;">
            <div class="hr_widgetstitle clearfix">
               <span><b>同步信息</b></span>
               <div class="configemail_self pull-right medium">同步职位或手动配置转发邮箱 <span><?php echo $_['resumeforward']['email']?></span> 接收简历 <a class="howtoaccept medium" href="javascript:;">如何配置？</a></div>
            </div>            
            <div class="hr_widgetscontent clearfix">
               <div class="synchronous_info synchronous_info_new">
                  <div><i class="config_51"></i>&nbsp;前程无忧</div>
                  <?php if(empty($thirdaccount_status_51job) || $thirdaccount_status_51job['result'] != 'syncing'): ?>
                  <?php 
                     $sync_51job_title = '下载职位信息并开始自动接收简历';
                     $sync_51job_iclass = '';
                     if(!empty($thirdaccount_status_51job)) {
                        $result = $thirdaccount_status_51job['result'];
                        if($result != 'captcha') {
                           if(!empty($thirdaccount_status_51job['msg'])) {
                              $sync_51job_title = $thirdaccount_status_51job['msg'];
                           } else {
                              if (!empty($thirdaccount_status_51job['time'])) {
                                 $sync_51job_title = JHtml::_('date', $thirdaccount_status_51job['time'], 'Y-m-d H:i:s') . " 同步成功";
                              } else {
                                 $sync_51job_title = "账号已同步";
                              }
                           }
                        }
                        if($result == 'success' || $result == 'error')
                           $sync_51job_iclass = 'config_' . $result;
                     }
                  ?>
                  <i class="<?=$sync_51job_iclass?>"></i>
                  <a href="#accountsetdialog_51job" class="ppp_bluebtn" id="sync_click_51job" data-syncaction='fetchjobs' data-vid="0"   data-autofetchon="<?=$autofetchjobs_on_51job ?>" data-type="51job" title="<?=$sync_51job_title?>">同步职位</a>
                  <?php else: ?>
                  <a href="javascript:;" class="ppp_whitebtn" title="职位同步中，请稍后">同步中...</a>
                  <?php endif; ?>
               </div>
               
               <div class="synchronous_info synchronous_info_new" style="margin-left:15px;">
                  <div><i class="config_zhilian"></i>&nbsp;智联招聘</div>
                  <?php if(empty($thirdaccount_status_zhilian) || $thirdaccount_status_zhilian['result'] != 'syncing'): ?>
                  <?php
                     $sync_zhilian_title = '下载职位信息并开始自动接收简历';
                     $sync_zhilian_iclass = '';
                     if(!empty($thirdaccount_status_zhilian)) {
                        $result = $thirdaccount_status_zhilian['result'];
                        if($result != 'captcha') {
                           if(!empty($thirdaccount_status_zhilian['msg'])) {
                              $sync_zhilian_title = $thirdaccount_status_zhilian['msg'];
                           } else {
                              if (!empty($thirdaccount_status_zhilian['time'])) {
                                 $sync_zhilian_title = JHtml::_('date', $thirdaccount_status_zhilian['time'], 'Y-m-d H:i:s') . " 同步成功";
                              } else {
                                 $sync_zhilian_title = "账号已同步";
                              }
                           }
                        }
                        if($result == 'success' || $result == 'error')
                           $sync_zhilian_iclass = 'config_' . $result;
                     }
                  ?>
                  <i class="<?=$sync_zhilian_iclass?>"></i>
                  <a href="#accountsetdialog_zhilian" class="ppp_bluebtn" id="sync_click_zhilian" data-syncaction='fetchjobs' data-vid="0" data-autofetchon="<?=$autofetchjobs_on_zhilian ?>" data-type="zhilian" title="<?=$sync_zhilian_title?>">同步职位</a>
                  <?php else: ?>
                  <a href="javascript:;" class="ppp_whitebtn" title="职位同步中，请稍后">同步中...</a>
                  <?php endif; ?>
               </div>

               <div class="synchronous_info synchronous_info_new" style="margin-left:15px;">
                  <div><i class="config_lagou"></i>&nbsp;拉勾</div>
                  <?php if(empty($thirdaccount_status_lagou) || $thirdaccount_status_lagou['result'] != 'syncing'): ?>
                  <?php
                     $sync_lagou_title = '下载职位信息并开始自动接收简历';
                     $sync_lagou_iclass = '';
                     if(!empty($thirdaccount_status_lagou)) {
                        $result = $thirdaccount_status_lagou['result'];
                        if($result != 'captcha') {
                           if(!empty($thirdaccount_status_lagou['msg'])) {
                              $sync_lagou_title = $thirdaccount_status_lagou['msg'];
                           } else {
                              if (!empty($thirdaccount_status_lagou['time'])) {
                                 $sync_lagou_title = JHtml::_('date', $thirdaccount_status_lagou['time'], 'Y-m-d H:i:s') . " 同步成功";
                              } else {
                                 $sync_lagou_title = "账号已同步";
                              }
                           }
                        }
                        if($result == 'success' || $result == 'error')
                           $sync_lagou_iclass = 'config_' . $result;
                     }
                  ?>
                  <i class="<?=$sync_lagou_iclass?>"></i>
                  <a href="#accountsetdialog_lagou" class="ppp_bluebtn" id="sync_click_lagou" data-syncaction='fetchjobs' data-vid="0" data-autofetchon="<?=$autofetchjobs_on_lagou ?>" data-type="lagou" title="<?=$sync_lagou_title?>">同步职位</a>
                  <?php else: ?>
                  <a href="javascript:;" class="ppp_whitebtn" title="职位同步中，请稍后">同步中...</a>
                  <?php endif; ?>
               </div>
               <div class="synchronous_info synchronous_info_new" style="margin-left:15px;">
                  <div><i class="config_jianzhu"></i>&nbsp;建筑英才</div>
                  <?php if(empty($thirdaccount_status_jiancai) || $thirdaccount_status_jiancai['result'] != 'syncing'): ?>
                  <?php
                     $sync_jiancai_title = '下载职位信息并开始自动接收简历';
                     $sync_jiancai_iclass = '';
                     if(!empty($thirdaccount_status_jiancai)) {
                        $result = $thirdaccount_status_jiancai['result'];
                        if($result != 'captcha') {
                           if(!empty($thirdaccount_status_jiancai['msg'])) {
                              $sync_jiancai_title = $thirdaccount_status_jiancai['msg'];
                           } else {
                              if (!empty($thirdaccount_status_jiancai['time'])) {
                                 $sync_jiancai_title = JHtml::_('date', $thirdaccount_status_jiancai['time'], 'Y-m-d H:i:s') . " 同步成功";
                              } else {
                                 $sync_jiancai_title = "账号已同步";
                              }
                           }
                        }
                        if($result == 'success' || $result == 'error')
                           $sync_jiancai_iclass = 'config_' . $result;
                     }
                  ?>
                  <i class="<?=$sync_jiancai_iclass?>"></i>
                  <a href="#accountsetdialog_jiancai" class="ppp_bluebtn" id="sync_click_jiancai" data-syncaction='fetchjobs' data-vid="0" data-autofetchon="<?=$autofetchjobs_on_jiancai ?>" data-type="jiancai"  title="<?=$sync_jiancai_title?>">同步职位</a>
                  <?php else: ?>
                  <a href="javascript:;" class="ppp_whitebtn" title="职位同步中，请稍后">同步中...</a>
                  <?php endif; ?>
               </div>
            </div> 
         </div>
         <?php endif; ?>
         <?php if(!$isJobManagerViewOnly):?>
         <div class="hr_widgetsbox hr_dongtaishow pull-right" style="width:46%;">
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
               <tr>
                  <th>动态</th>
                  <th>最近1个月</th>
                  <th>最近7天</th>
                  <th>最近3天</th>
               </tr>
               <?php if($totalresumes['1m']>0 || $totalresumes['1w']>0 || $totalresumes['3d']>0): ?>
               <tr>
                  <td>简历</td>
                  <td><span><?php echo $totalresumes['1m']?$totalresumes['1m']:0; ?></span></td>
                  <td><span><?php echo $totalresumes['1w']?$totalresumes['1w']:0; ?></span></td>
                  <td><span><?php echo $totalresumes['3d']?$totalresumes['3d']:0; ?></span></td>
               </tr>
               <?php else: ?>
               <tr>
                  <td>简历</td>
                  <td colspan="4" class="nodatatd yahei">暂无信息，请您先 <a href="<?php echo OC_Helper::linkToRoute("company_synchronousinfo")?>">同步职位</a> 或 <a href="<?php echo OC_Helper::linkToRoute("resume_showaddform")?>">创建简历</a></td>
               </tr>
               <?php endif; ?>
               <?php if($totalinterview['1m']>0 || $totalinterview['1w']>0 || $totalinterview['3d']>0): ?>
               <tr class="lasttr">
                  <td>面试</td>
                  <td><span><?php echo $totalinterview['1m']?$totalinterview['1m']:0; ?></span></td>
                  <td><span><?php echo $totalinterview['1w']?$totalinterview['1w']:0; ?></span></td>
                  <td><span><?php echo $totalinterview['3d']?$totalinterview['3d']:0; ?></span></td>
               </tr>
               <?php else: ?>
               <tr class="lasttr">
                  <td>面试</td>
                  <td colspan="4" class="nodatatd yahei">暂无信息，请您先 <a id="setinterview" style="margin-left:0px;" href="<?php echo OC_Helper::linkToRoute("calendar_home").'?adddialog=1'; ?>">安排面试</a></td>
               </tr>
               <?php endif; ?>
               
            </table>
         </div>
         <?php endif; ?>
      </div>
   </div>
   <?php if(!$isJobManagerViewOnly):?>
   <div class="hr_companycenter_resumeshow clearfix" id="summarylist">
      <img src="/images/3/blue-loading.gif">
   </div>
   <?php endif; ?>
</div>
<?php if(!$isJobManagerViewOnly):?>
<div class="hr_net_tipdialog popup" id="hr_howtoconfig" style="width:260px; display:none; top:auto; left:auto;">
   <div class="hr_net_point"></div>
   <div class="closediv"></div>
	<div class="hr_net_tipcontent">
	   <p>1. 登录<a href="http://ehire.51job.com/MainLogin.aspx" target="_blank">前程无忧</a> / <a href="http://hr.zhaopin.com/hrclub/index.html" target="_blank">智联招聘</a> / <a href="http://ent.buildhr.com/login" target="_blank">建筑英才</a></p>
      <p>2. 进入已发布的职位详情页</p>
      <p class="clearfix"><em class="pull-left">3.</em> <em class="blockstyle">找到<b>简历接收方式</b>，填写云招聘邮箱<br/>地址 <b class="yellowcolor"><?php echo $_['resumeforward']['email']?></b></em></p>
      <p class="textright"><a target="_blank" href="<?=JURI::base()?>helps/doc/product/resumeforward_51job.html">查看详细帮助</a></p>
   </div>
</div>
<?php endif; ?>
<!-- Modal 51job -->
<div id="accountsetdialog_51job" class="modal hide fade accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<!-- Modal zhilian -->
<div id="accountsetdialog_zhilian" class="modal hide fade accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<!-- Modal lagou -->
<div id="accountsetdialog_lagou" class="modal hide fade accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<!-- Modal jiancai -->
<div id="accountsetdialog_jiancai" class="modal hide fade accountsetdialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<div id="preview_holder" class="modal changeinterview_dialog popup" style="display:none; max-width:500px; position:absolute; z-index:100;"></div>

<!-- 企业中心自动同步确认dialog -->
<div class="modal hide fade autorenew_dialog" id="autofetchjobs">
</div>
<div class="modal hide fade autorenew_dialog" id="autofetchjobs_successdialog">  
</div>
